/*   1:    */ package nl.siegmann.epublib.html.htmlcleaner;
/*   2:    */ 
/*   3:    */ import java.util.Iterator;
/*   4:    */ import java.util.List;
/*   5:    */ import java.util.Map;
/*   6:    */ import java.util.Map.Entry;
/*   7:    */ import java.util.Set;
/*   8:    */ import javax.xml.stream.XMLEventReader;
/*   9:    */ import javax.xml.stream.XMLStreamException;
/*  10:    */ import javax.xml.stream.XMLStreamWriter;
/*  11:    */ import javax.xml.stream.events.XMLEvent;
/*  12:    */ import org.htmlcleaner.CleanerProperties;
/*  13:    */ import org.htmlcleaner.CommentNode;
/*  14:    */ import org.htmlcleaner.ContentNode;
/*  15:    */ import org.htmlcleaner.EndTagToken;
/*  16:    */ import org.htmlcleaner.TagNode;
/*  17:    */ 
/*  18:    */ public class XmlEventSerializer
/*  19:    */   implements XMLEventReader
/*  20:    */ {
/*  21:    */   protected CleanerProperties props;
/*  22:    */   
/*  23:    */   protected XmlEventSerializer(CleanerProperties props)
/*  24:    */   {
/*  25: 23 */     this.props = props;
/*  26:    */   }
/*  27:    */   
/*  28:    */   public void writeXml(TagNode tagNode, XMLStreamWriter writer)
/*  29:    */     throws XMLStreamException
/*  30:    */   {
/*  31: 44 */     serialize(tagNode, writer);
/*  32:    */     
/*  33: 46 */     writer.flush();
/*  34:    */   }
/*  35:    */   
/*  36:    */   protected void serializeOpenTag(TagNode tagNode, XMLStreamWriter writer)
/*  37:    */     throws XMLStreamException
/*  38:    */   {
/*  39: 50 */     String tagName = tagNode.getName();
/*  40:    */     
/*  41: 52 */     writer.writeStartElement(tagName);
/*  42: 53 */     Map tagAtttributes = tagNode.getAttributes();
/*  43: 54 */     for (Iterator it = tagAtttributes.entrySet().iterator(); it.hasNext();)
/*  44:    */     {
/*  45: 55 */       Map.Entry entry = (Map.Entry)it.next();
/*  46: 56 */       String attName = (String)entry.getKey();
/*  47: 57 */       String attValue = (String)entry.getValue();
/*  48: 59 */       if ((this.props.isNamespacesAware()) || ((!"xmlns".equals(attName)) && (!attName.startsWith("xmlns:")))) {
/*  49: 62 */         writer.writeAttribute(attName, attValue);
/*  50:    */       }
/*  51:    */     }
/*  52:    */   }
/*  53:    */   
/*  54:    */   protected void serializeEmptyTag(TagNode tagNode, XMLStreamWriter writer)
/*  55:    */     throws XMLStreamException
/*  56:    */   {
/*  57: 67 */     String tagName = tagNode.getName();
/*  58:    */     
/*  59: 69 */     writer.writeEmptyElement(tagName);
/*  60: 70 */     Map tagAtttributes = tagNode.getAttributes();
/*  61: 71 */     for (Iterator it = tagAtttributes.entrySet().iterator(); it.hasNext();)
/*  62:    */     {
/*  63: 72 */       Map.Entry entry = (Map.Entry)it.next();
/*  64: 73 */       String attName = (String)entry.getKey();
/*  65: 74 */       String attValue = (String)entry.getValue();
/*  66: 76 */       if ((this.props.isNamespacesAware()) || ((!"xmlns".equals(attName)) && (!attName.startsWith("xmlns:")))) {
/*  67: 79 */         writer.writeAttribute(attName, attValue);
/*  68:    */       }
/*  69:    */     }
/*  70:    */   }
/*  71:    */   
/*  72:    */   protected void serializeEndTag(TagNode tagNode, XMLStreamWriter writer)
/*  73:    */     throws XMLStreamException
/*  74:    */   {
/*  75: 84 */     writer.writeEndElement();
/*  76:    */   }
/*  77:    */   
/*  78:    */   protected void serialize(TagNode tagNode, XMLStreamWriter writer)
/*  79:    */     throws XMLStreamException
/*  80:    */   {
/*  81: 89 */     if (tagNode.getChildren().isEmpty())
/*  82:    */     {
/*  83: 90 */       serializeEmptyTag(tagNode, writer);
/*  84:    */     }
/*  85:    */     else
/*  86:    */     {
/*  87: 92 */       serializeOpenTag(tagNode, writer);
/*  88:    */       
/*  89: 94 */       List tagChildren = tagNode.getChildren();
/*  90: 95 */       for (Iterator childrenIt = tagChildren.iterator(); childrenIt.hasNext();)
/*  91:    */       {
/*  92: 96 */         Object item = childrenIt.next();
/*  93: 97 */         if (item != null) {
/*  94: 98 */           serializeToken(item, writer);
/*  95:    */         }
/*  96:    */       }
/*  97:101 */       serializeEndTag(tagNode, writer);
/*  98:    */     }
/*  99:    */   }
/* 100:    */   
/* 101:    */   private void serializeToken(Object item, XMLStreamWriter writer)
/* 102:    */     throws XMLStreamException
/* 103:    */   {
/* 104:107 */     if ((item instanceof ContentNode)) {
/* 105:108 */       writer.writeCharacters(((ContentNode)item).getContent().toString());
/* 106:109 */     } else if ((item instanceof CommentNode)) {
/* 107:110 */       writer.writeComment(((CommentNode)item).getContent().toString());
/* 108:111 */     } else if (!(item instanceof EndTagToken)) {
/* 109:113 */       if ((item instanceof TagNode)) {
/* 110:114 */         serialize((TagNode)item, writer);
/* 111:    */       }
/* 112:    */     }
/* 113:    */   }
/* 114:    */   
/* 115:    */   public void close()
/* 116:    */     throws XMLStreamException
/* 117:    */   {}
/* 118:    */   
/* 119:    */   public String getElementText()
/* 120:    */     throws XMLStreamException
/* 121:    */   {
/* 122:129 */     return null;
/* 123:    */   }
/* 124:    */   
/* 125:    */   public Object getProperty(String name)
/* 126:    */     throws IllegalArgumentException
/* 127:    */   {
/* 128:136 */     return null;
/* 129:    */   }
/* 130:    */   
/* 131:    */   public boolean hasNext()
/* 132:    */   {
/* 133:143 */     return false;
/* 134:    */   }
/* 135:    */   
/* 136:    */   public XMLEvent nextEvent()
/* 137:    */     throws XMLStreamException
/* 138:    */   {
/* 139:150 */     return null;
/* 140:    */   }
/* 141:    */   
/* 142:    */   public XMLEvent nextTag()
/* 143:    */     throws XMLStreamException
/* 144:    */   {
/* 145:157 */     return null;
/* 146:    */   }
/* 147:    */   
/* 148:    */   public XMLEvent peek()
/* 149:    */     throws XMLStreamException
/* 150:    */   {
/* 151:164 */     return null;
/* 152:    */   }
/* 153:    */   
/* 154:    */   public Object next()
/* 155:    */   {
/* 156:171 */     return null;
/* 157:    */   }
/* 158:    */   
/* 159:    */   public void remove() {}
/* 160:    */ }


/* Location:           C:\Users\David\workspace\CosaRaraPorqueSi\main\epublib-tools-3.1.jar
 * Qualified Name:     nl.siegmann.epublib.html.htmlcleaner.XmlEventSerializer
 * JD-Core Version:    0.7.0.1
 */